package com.hspedu.newData.dmsxl.数组.左右数组;

import org.junit.Test;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-04-29 
 * @Version: 1.0
 */

public class LC238除自身以外的乘积 {

    public int[] productExceptSelf(int[] nums) {

        int len = nums.length;
        int[] numsLeft = new int[len];
        int[] numsRight = new int[len];
        numsLeft[0] = 1;
        numsRight[len-1] = 1;
        for (int i = 1; i < len; i++) {
            numsLeft[i] = nums[i-1]*numsLeft[i-1];
        }
        for (int i = len - 2; i >= 0; i--) {
            numsRight[i] = nums[i+1]*numsRight[i+1];
        }

        int[] res = new int[len];
        for (int i = 0; i < len; i++) {
            res[i] = numsLeft[i]*numsRight[i];
        }

        return res;
    }

    @Test
    public void test() {
        // 测试代码

        int[] ints = productExceptSelf(new int[]{-1,1,0,-3,3});
        System.out.println("111");

    }
}
